package com.shhm.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.admin.mapper.BannerMapper;
import com.shhm.admin.service.BannerService;
import com.shhm.admin.util.RequestUtil;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.entity.common.BannerEntity;
import com.shhm.common.utils.MybatisPlusUtil;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/11 下午7:35
 */
@Service
public class BannerServiceImpl implements BannerService {
    @Resource
    private BannerMapper bannerMapper;

    @Override
    public AjaxResultPlus pageList(Integer pageNum, Integer pageSize, Integer isPage, HttpServletRequest request) {
        PageDTO<BannerEntity> userPage = new PageDTO<>(pageNum, pageSize);
//        String userOperatePerms = RequestUtil.getUserOperatePerms(request, roleOperatePermsMapper);
//        if (userOperatePerms.equals("NOT_PERMISSION")) return AjaxResultPlus.error(403,"您无权查看数据");
        PageDTO<BannerEntity> list=bannerMapper.selectPage(userPage, null);
        return AjaxResultPlus.custom(200, false)
                .put("data",list)
                .put("operateStr","*");
    }

    @Override
    public AjaxResultPlus pageSearchList(Integer pageNum, Integer pageSize, BannerEntity entity) {
        PageDTO<BannerEntity> userPage = new PageDTO<>(pageNum, pageSize);
        QueryWrapper<BannerEntity> qw = MybatisPlusUtil.buildSearchQueryWrapper(entity);
        PageDTO<BannerEntity> list = bannerMapper.selectPage(userPage, qw);
        return AjaxResultPlus.success(list,false);
    }

    @Override
    public AjaxResultPlus add(BannerEntity entity) {
        entity.createLocalDateTime();
        return ResponseUtil.sqlExeIsSuccess(bannerMapper.insert(entity));
    }

    @Override
    public AjaxResultPlus update(BannerEntity entity) {
        return ResponseUtil.sqlExeIsSuccess(bannerMapper.updateById(entity));
    }

    @Override
    public AjaxResultPlus delete(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(bannerMapper.deleteByIds(list));
    }
}
